home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2002 January / PC Answers January 2002.7z / PC Answers January 2002.bin / graphics / freepixl / _SETUP.1 / geocorrect.pxl < prev    next >
Text File  |  2000-09-17  |  11KB  |  350 lines

  1. {    Filename    :     geocorrect.pxl
  2.      Purpose    :    Demonstrate the geocorrect command
  3.     Date        :    January 18, 2000
  4.     Author        :    Stewart DIBBS, VYSOR Integration Inc
  5. History:
  6.  
  7.     Version    :      4.40    RELEASE
  8.     Update        :  
  9.     Date        :  
  10.  
  11. --------------------------------------------------------------------------}
  12. Initialize: {only one instance allowed}
  13.     UseCoordinates(PIXEL)
  14.     Title$ = "Using the GeoCorrection commands"                                  
  15.     WinExist(Title$,Res)
  16.     If Res = 0 Then Goto One_Instance
  17.     Beep
  18.     WinSetActive(Title$,Res)
  19.     WinShow(Title$,RESTORE,Res)
  20.     End
  21. One_Instance:
  22.     UseCaption(Title$) {change the title}
  23.     UseBackground(TRANSPARENT,0,128,192)     
  24.     WinShow(Title$,NOTOPMOST,Res) 
  25.     DrawBackGround
  26.     WinLocate(Title$,92,66,978,680,Res)                
  27.     DirGet(SourceDir$) {used later for library function calls}
  28.  
  29.     DragAcceptFile(ENABLE,AcceptFile)
  30.     AutoProgressBar(DISABLE)
  31.  
  32.     InitFile$ = "*.bmp"
  33.  
  34.     InfoMenu(REMOVE)
  35.     WaitInput(100)
  36.     SetMenu("&File",IGNORE,
  37.         "&New",CreatingFile,
  38.         "&Open",OpeningFile,
  39.         "&Save",SavingFile,
  40.         SEPARATOR,
  41.         "E&xit!",Terminate,
  42.         ENDPOPUP,
  43.         "&View",IGNORE,
  44.         "&ToolBar",ViewToolBar,
  45.         "&StatusBar",ViewStatusBar,
  46.         ENDPOPUP,
  47.         "&Information",IGNORE,
  48.         "&Concept",Concept,
  49.         "&Help",ShowAppHelp,
  50.         SEPARATOR,
  51.         "&About",About,
  52.         ENDPOPUP)
  53.  
  54.     GoSub MakeToolbar
  55.     ChangeMenuItem("&ToolBar",CHECK,TBRes)
  56.  
  57.         
  58.     StatusWindow(ENABLE,BOTTOM,3,400,600,-1,0)
  59.     DrawStatusWinText(0,"Ready")
  60.     ChangeMenuItem("&StatusBar",CHECK,SBRes)
  61.  
  62.     GoSub InfoMessage_0    
  63.  
  64.     
  65. Wait_for_Input:
  66.     WaitInput()
  67.  
  68. Terminate:
  69.     End
  70.  
  71.  
  72. Concept:
  73.     MessageBox(OK,1,INFORMATION,
  74. "This is a skeleton of a PiXCL application.  You could briefly
  75. describe your application's function here, or provide some
  76. basic help information.",
  77.     "PiXCL Skeleton Concept",Res)
  78.  
  79.     Goto Wait_for_Input
  80.  
  81. ShowAppHelp:
  82.     {An application Help file usually has the same name as the application.}
  83.     Winhelp("geocorrect.hlp",CONTENTS,"")
  84.  
  85.     Goto Wait_for_Input
  86.  
  87. About:
  88.     AboutUser("Using the GeoCorrection commands",  { or substitute Title$}
  89.       "Two lines of text goes here e.g. Application function.",
  90.     "Four Lines of additional information goes here, perhaps contact information and Web addresses")   
  91.  
  92.     Goto Wait_for_Input
  93.  
  94. ViewToolBar:
  95.     GetMenuStatus("&ToolBar",CHECKED,Res)
  96.     If Res = 0
  97.         GoSub MakeToolbar
  98.         ChangeMenuItem("&ToolBar",CHECK,Res)
  99.     Else
  100.         Toolbar()
  101.         ChangeMenuItem("&ToolBar",UNCHECK,Res)
  102.     Endif
  103.     Goto Wait_for_Input
  104.  
  105. ViewStatusBar:
  106.     GetMenuStatus("&StatusBar",CHECKED, Res)
  107.     If Res = 0
  108.         StatusWindow(ENABLE,BOTTOM,3,400,200,-1,0)
  109.         DrawStatusWinText(0,"Ready")
  110.         ChangeMenuItem("&StatusBar",CHECK,Res)
  111.     Else
  112.         StatusWindow(DISABLE,BOTTOM,3,400,200,-1,0)
  113.        ChangeMenuItem("&StatusBar",UNCHECK,Res)
  114.     Endif
  115.     Goto Wait_for_Input
  116.  
  117. CreatingFile:
  118.     WaitInput(1)
  119.     {TODO: add file handling here}
  120.     MessageBox(OK,1,INFORMATION,"No operations coded for this button.",
  121.                     "Creating File",Res)
  122.     Goto Wait_for_Input
  123.  
  124. OpeningFile:
  125.     WaitInput(1)
  126.     DrawBackGround
  127.     SetMouse()
  128.     SetRightMouse()
  129.     Histogram()
  130.     WaitInput(1)
  131.     If ImageFile$ <> "" Then FreeBitMap(ImageFile$)
  132.     FileGet(Filter$, InitFile$, "",
  133.         "Select an image to load",CHANGEDIR,ImageFile$)
  134.     If ImageFile$ = "" Then Goto Wait_for_Input
  135.  
  136. ProcessImage:
  137.     If DFServer <> 1
  138.     FileExtension(ImageFile$,Ext$,Res)
  139.     InitFile$ = "*." + Ext$
  140.     Ext$ = Ext$ + " Image File Format Read"
  141.     GetBitMapDim(ImageFile$,Lines,Pixels,Bits)
  142.     DrawBackGround
  143.     DrawShadowText(25,0,Ext$,255,255,255,1)
  144.     DrawShadowText(560,30,"Lines",0,0,0,1) DrawShadowNumber(660,30,Lines,0,0,0,1)
  145.     DrawShadowText(560,50,"Pixels",0,0,0,1) DrawShadowNumber(660,50,Pixels,0,0,0,1)
  146.     DrawShadowText(560,70,"Bits",0,0,0,1) DrawShadowNumber(660,70,Bits,0,0,0,1)
  147.  
  148.     If Bits <> 0
  149.         sx1 = 47  sy1 =65
  150.         sx2 = 53 + Pixels    sy2 = 71 + Lines
  151.         DrawEdgeRectangle(sx1,sy1,sx2,sy2,SUNKENEDGE,ADJUST,RECT)
  152.         DrawBitmap(50,68,ImageFile$)
  153.         DrawSizedBitmap(580,250,830,453,ImageFile$)
  154.         DrawShadowText(590,455,"Original image thumbnail",0,0,0,1)
  155.     Endif
  156.  
  157.     Else
  158.         DropFileServer(ENABLE,ImageFile$)
  159.         WinGetClientRect("",cx1,cy1,cx2,cy2)
  160.         SetMouse(cx1,cy1,cx2,cy2,EndDFS,n,n)
  161.     Endif
  162.     
  163.     ChangeToolbarBtn("",7,ENABLED,Res)
  164.     ChangeToolbarBtn("",8,ENABLED,Res)
  165.     ChangeToolbarBtn("",9,ENABLED,Res)
  166.     Goto Wait_for_Input
  167.  
  168. SavingFile:
  169.     WaitInput(1)
  170.     {TODO: add file handling here}
  171.     MessageBox(OK,1,INFORMATION,
  172. "The images loaded into the PiXCL image list are still in memory, and can be saved using the 
  173. SaveBitmap command.",
  174.     "Saving geometrically corrected files",Res)
  175.     Goto Wait_for_Input
  176.  
  177. PrintingFile:
  178.     WaitInput(1)
  179.     {TODO: add file handling here}
  180.     MessageBox(OK,1,INFORMATION,"No operations coded for this button.",
  181.                     "Printing File",Res)
  182.     Goto Wait_for_Input
  183.  
  184. AcceptFile:
  185.     GetDragList(FileList$)
  186.     {TODO: add file list handling here, or delete this whole label handler}
  187.     Goto Wait_for_Input
  188.  
  189.  
  190. Reporter:
  191.     rx -= 50
  192.     ry -= 68
  193.     GoSub ConvertCoords
  194.     Goto Wait_for_Input
  195.  
  196. ConvertCoords: {subroutine}
  197.     Str(rx,rx$) 
  198.     Str(ry,ry$)
  199.     Msg$ = "image_X = " + rx$
  200.     DrawStatusWinText(1,Msg$)
  201.     Msg$ = "image_Y = " + ry$
  202.     DrawStatusWinText(2,Msg$)
  203.     Return 
  204.     
  205. GeoCorrectionNN:
  206.     Rmode = 1
  207.     GetBackground(R,G,B)
  208.     UseBrush(SOLID,R,G,B)   UsePen(NULL,1,0,0,0)
  209.     DrawRectangle(610,200,830,220)
  210.     UseFont("Arial",0,19,BOLD,NOITALIC,NOUNDERLINE,255,255,255)
  211.     DrawShadowText(610,200,"Nearest Neighbour Mode",0,0,0,1)
  212.     Goto GeoCorrection
  213. GeoCorrectionBL:
  214.     Rmode = 2
  215.     GetBackground(R,G,B)
  216.     UseBrush(SOLID,R,G,B)  UsePen(NULL,1,0,0,0)
  217.     DrawRectangle(610,200,830,220)
  218.     UseFont("Arial",0,19,BOLD,NOITALIC,NOUNDERLINE,255,255,255)
  219.     DrawShadowText(610,200,"Bilinear Interpolation Mode",0,0,0,1)
  220.     Goto GeoCorrection
  221. GeoCorrectionBC:
  222.     Rmode = 3
  223.     GetBackground(R,G,B)
  224.     UseBrush(SOLID,R,G,B)   UsePen(NULL,1,0,0,0)
  225.     DrawRectangle(610,200,830,220)
  226.     UseFont("Arial",0,19,BOLD,NOITALIC,NOUNDERLINE,255,255,255)
  227.     DrawShadowText(610,200,"Bicubic Convolution Mode",0,0,0,1)
  228. GeoCorrection:
  229.     Msg$ = "No image has been loaded."
  230.     If ImageFile$ = "" Then MessageBox(OK,1,EXCLAMATION,Msg$,"Unable to do GeoCorrect process",Res) Goto Wait_for_Input
  231.     xx2 = sx2 - 2 
  232.     yy2 = sy2 - 2
  233.     WinGetClientRect("",cx1,cy1,cx2,cy2)
  234.     UsePen(SOLID,1,255,0,0)
  235.     UseBrush(NULL,0,0,0)
  236.     DrawStatusWinText(0,"Click bottom right point #1")
  237.     SetMouse(cx1,cy1,cx2,cy2,GeoPt2,x1,y1)
  238.     SetRightMouse(0,0,540,454,Reporter,rx,ry)
  239.     WaitInput()
  240. GeoPt2:
  241.     DrawPoint(x1,y1,CIRCLE)
  242.     x1 -= 50    y1 -= 68    y1 = Lines - y1
  243.     rx = x1  ry = y1
  244.     GoSub ConvertCoords
  245.     DrawStatusWinText(0,"Click bottom left point #2")
  246.     SetMouse(cx1,cy1,cx2,cy2,GeoPt3,x2,y2)
  247.     WaitInput()
  248. GeoPt3:
  249.     DrawPoint(x2,y2,CIRCLE)
  250.     x2 -= 50   y2 -= 68      y2 = Lines - y2
  251.     rx = x2  ry = y2
  252.     GoSub ConvertCoords
  253.     DrawStatusWinText(0,"Click top left point #3")
  254.     SetMouse(cx1,cy1,cx2,cy2,GeoPt4,x3,y3)
  255.     WaitInput()
  256. GeoPt4:
  257.     DrawPoint(x3,y3,CIRCLE)
  258.     x3 -= 50  y3 -= 68    y3 = Lines - y3
  259.     rx = x3  ry = y3
  260.     GoSub ConvertCoords
  261.     DrawStatusWinText(0,"Click top right point #4")
  262.     SetMouse(cx1,cy1,cx2,cy2,GeoDone,x4,y4)
  263.     WaitInput()
  264. GeoDone:
  265.     SetMouse()
  266.     DrawPoint(x4,y4,CIRCLE)
  267.     x4 -= 50    y4 -= 68    y4 = Lines - y4
  268.     rx = x4  ry = y4
  269.     GoSub ConvertCoords
  270.     DrawStatusWinText(0,"Correcting image ...")
  271.     UseCursor(WAIT)
  272.     If Rmode = 3 Then GeoCorrectImage(x1,y1,x2,y2,x3,y3,x4,y4,BICUBIC,Res)
  273.     If Rmode = 2 Then GeoCorrectImage(x1,y1,x2,y2,x3,y3,x4,y4,BILINEAR,Res)
  274.     If Rmode = 1 Then GeoCorrectImage(x1,y1,x2,y2,x3,y3,x4,y4,NEAREST,Res)
  275.     UseCursor(ARROW)
  276.     If Res <> 0
  277.         FlipImage(VERT,Res)
  278.         DrawBitmap(50,68,ImageFile$)
  279.         Save$ = SourceDir$ + "\transformedimage.bmp"
  280.         SaveBitmap(Save$,Res)
  281.     Else
  282.         MessageBox(OK,1,EXCLAMATION, "Geo Correct operation Failed","App Message",Res)
  283.     Endif
  284.     DrawStatusWinText(0,"Ready")
  285.     DrawStatusWinText(1,"")
  286.     DrawStatusWinText(2,"")
  287.     WaitInput(1200)
  288.     GoSub InfoMessage_1
  289.     Goto Wait_for_Input
  290.  
  291.  
  292.  
  293. {--- Style Suggestion: place all subroutines at the end of the script.}
  294.  
  295. MakeToolbar: {subroutine}
  296.     Toolbar(RAISED, PXL_SMALL,
  297.         NULL, NULL, SEPARATOR, "", Wait_for_Input, 
  298.         PXL_NEW, ENABLED, STD, "FileNew", CreatingFile,
  299.         PXL_OPEN, ENABLED, STD, "FileOpen", OpeningFile, 
  300.         PXL_SAVE, ENABLED, STD, "FileSave", SavingFile, 
  301.         PXL_PRINT,  ENABLED, STD,"PrintFile", PrintingFile, 
  302.         NULL, NULL, SEPARATOR, "", Wait_for_Input, 
  303.         HELPER_1, DISABLED, STD,"GeoCorrect with Nearest Neighbour", GeoCorrectionNN, 
  304.         HELPER_2, DISABLED, STD,"GeoCorrect with Bilinear Interpolation", GeoCorrectionBL, 
  305.         HELPER_3, DISABLED, STD,"GeoCorrect with Bicubic Convolution", GeoCorrectionBC, 
  306.         NULL, NULL, SEPARATOR, "", Wait_for_Input, 
  307.         HELPINFO, ENABLED, STD,"Show Help",ShowAppHelp) 
  308.  
  309.     Return
  310.  
  311. InfoMessage_0:
  312.     UseFont("Arial",0,37,BOLD,NOITALIC,NOUNDERLINE,255,255,255)
  313.     DrawShadowText(35,60,"Geometric Correction Commands in PiXCL 4.4",0,0,0,2)
  314.     UseFont("Arial",0,19,BOLD,NOITALIC,NOUNDERLINE,255,255,255)
  315.     DrawShadowTextExt(60,100,750,600,
  316. "Any bitmap image loaded into the PIXCL image list can be distorted geometrically using the set of commands including
  317.         GeoCorrectImage  - transform the image using 4 ''corner'' points
  318.         GeoTranslateImage  -  translate the image relative to a corner point
  319.         RotateImage  -  rotate about the center pixel by an arbitrary degree
  320.         RotateImageExt  -  rotate the image about a selected point
  321.         ResampleImage  -   change the dimensions of the image
  322.  
  323. All these commands use one of three possible pixel resampling methods:
  324.     NEAREST NEIGHBOUR  -  the fastest, but with limitations to the acuracy of pixel values;
  325.     BILINEAR  - slower, but provides better radiometric results;
  326.     BICUBIC-  slowest, but gives the best results for the interpolated pixel values.
  327.  
  328.             To continue, open one of the sample images e.g. BRSFC754.BMP",
  329.     LEFT, 0,0,0,1)
  330.  
  331.  
  332.     UseFont("MS Sans Serif",0,19,NOBOLD,NOITALIC,NOUNDERLINE,255,0,0)
  333.     Return
  334.  
  335. InfoMessage_1:
  336.     MessageBox(OK,1,INFORMATION,
  337. "The four points you selected, either inside and/or outside the image, become the new
  338. corner points for the corrected image.  Hence, if a selected point is inside the image, 
  339. that point (relative to the current corner) becomes the new corner.
  340.  
  341. Conversely, a point OUTSIDE the image becomes the new adjacent corner, warping all the
  342. pixel values and positions accordingly.
  343.  
  344. Note that is all cases, the image dimensions are unchanged. Only the relative position of the 
  345. pixels within the image are changed. It is possible to resample so that there are unpopulated
  346. regions, which get set to black, and other regions that no longer fall within the boundaries
  347. of the image.",
  348.     "What's happened here ?",Res)
  349.  
  350.     Return